﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _2_12
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            double totalAmount = double.Parse(textBox1.Text);
            int count = int.Parse(textBox1.Text);
            double[] redPackets = new double[count];
            Random random = new Random();
            double remaining = totalAmount;
            string redPacketsText = "";

          
            for (int i = 0; i < count - 1; i++)
            {
              
                double amount = random.NextDouble() * remaining / 2;
                amount = Math.Round(amount, 2);
                redPackets[i] = amount;
                remaining -= amount;
                redPacketsText += amount + "  ";
             
                if ((i + 1) % 5 == 0)
                {
                    redPacketsText += Environment.NewLine;
                }
            }
          
            redPackets[count - 1] = Math.Round(remaining, 2);
            redPacketsText += redPackets[count - 1];

            textBox3.Text = redPacketsText;

        
            double sum = 0;
            foreach (double amount in redPackets)
            {
                sum += amount;
            }
            textBox4.Text = sum.ToString("F2");
        }
    }
}